package com.demo.backtemplate.mappers;

import com.demo.backtemplate.models.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 商品Mapper接口
 */
@Mapper
public interface ProductMapper {
    @Select("SELECT * FROM product WHERE id = #{id}")
    Product findById(@Param("id") Long id);

    @Select("SELECT * FROM product WHERE status = 1")
    List<Product> findAll();

    @Select("SELECT * FROM product WHERE status = 1 LIMIT #{offset}, #{size}")
    List<Product> findAllWithPagination(@Param("offset") int offset, @Param("size") int size);

    @Insert("INSERT INTO product (name, description, price, image_url, status) " +
            "VALUES (#{name}, #{description}, #{price}, #{imageUrl}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Product product);

    @Update("UPDATE product SET name = #{name}, description = #{description}, " +
            "price = #{price}, image_url = #{imageUrl}, status = #{status} " +
            "WHERE id = #{id}")
    int update(Product product);

    @Update("UPDATE product SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);

    @Delete("DELETE FROM product WHERE id = #{id}")
    int delete(@Param("id") Long id);
} 